//
//  UIView+PP.m
//  pickpic
//
//  Created by Jinxiao on 9/4/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "UIView+PP.h"

@implementation UIView (PP)

+ (void)load {
    [self swizzleMethod:@selector(didMoveToSuperview) withMethod:@selector(swizzled_didMoveToSuperview) error:nil];
}

- (void)swizzled_didMoveToSuperview {
    [self swizzled_didMoveToSuperview];

    if([self isKindOfClass:[UIControl class]]) {
        self.exclusiveTouch = YES;
    }
}

- (MBProgressHUD *)toastMessage:(NSString *)message {
    return [self toastMessage:message duration:2];
}

- (MBProgressHUD *)toastMessage:(NSString *)message duration:(NSTimeInterval)duration {
    return [self toastMessage:message duration:duration completion:nil];
}

- (MBProgressHUD *)toastMessage:(NSString *)message duration:(NSTimeInterval)duration completion:(void (^)(void))completion {
    [MBProgressHUD hideAllHUDsForView:self animated:NO];

    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self];
    [self addSubview:hud];

    hud.minShowTime = duration;
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabelText = message;
    [hud showAnimated:YES whileExecutingBlock:^{

    } completionBlock:^{
        !completion ? : completion();
    }];

    return hud;
}

@end
